package com.healthyeating.manage.controller;

import com.healthyeating.common.annotation.Log;
import com.healthyeating.common.core.controller.BaseController;
import com.healthyeating.common.core.domain.AjaxResult;
import com.healthyeating.common.enums.BusinessType;
import com.healthyeating.manage.domain.Message;
import com.healthyeating.manage.service.IMessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.healthyeating.common.core.domain.AjaxResult.success;

/**
 * 私信Controller
 *
 * @author 段奇乐
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/manage/message")
public class MessageController extends BaseController {

    @Autowired
    private IMessageService messageService;

    /**
     * 查询食材过期的通知列表
     */
    @GetMapping("/list/{role}")
    public AjaxResult list(@PathVariable String role) {
        return success(messageService.list(role));
    }

    /**
     * 编辑消息
     */
    @PutMapping
    @Log(title = "私信", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody Message message) {
        return toAjax(messageService.updateMessage(message));
    }

    /**
     * 新增消息
     */
    @PostMapping
    @Log(title = "私信", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody Message message) {
        return toAjax(messageService.insertMessage(message));
    }

    /**
     * 批量修改消息
     */
    @PutMapping("batch")
    @Log(title = "私信", businessType = BusinessType.UPDATE)
    public AjaxResult batchEdit(@RequestBody List<Message> messageList) {
        return toAjax(messageService.batchUpdateMessage(messageList));
    }
}
